<template>
  <el-card style="max-width: 480px">
    <template #header>
      <div class="card-header">
        <span>基本信息</span>
        <el-icon @click="getTableData()">
          <Refresh/>
        </el-icon>
      </div>
    </template>

    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="昵称">
        <el-input v-model="form.nickname"/>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.phone"/>
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="form.sex">
          <el-radio :value="1" :label="1">男</el-radio>
          <el-radio :value="0" :label="0">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
<!--        <el-button>保存</el-button>-->
      </el-form-item>
    </el-form>


  </el-card>
</template>
<script lang="ts" setup>
import {onMounted, reactive, ref} from 'vue'
import {showTips, successTips, warningTips} from "@/utils/util";

import {getEnterpriseInfoApi, updateMyInfoApi} from "@/api/enterprise";

// do not use same name with ref
const form = reactive({
  nickname: '',
  sex: 1,
  email: "",
  phone: "",

})
onMounted(()=>{
  getEnterpriseInfoApi().then((response: any) => {
    if (response.code === 200) {
      Object.assign(form,response.data[0])
    } else {
      warningTips(response.message)
    }
  })
})
const onSubmit = () => {
  updateMyInfoApi(form).then((response: any) => {
    if (response.code === 200) {
      Object.assign(form,response.data[0])
      successTips(response.message)
    } else {
      warningTips(response.message)
    }
  })
}
const getTableData = () => {
  getEnterpriseInfoApi().then((response: any) => {
    if (response.code === 200) {
      Object.assign(form,response.data[0])
      successTips(response.message)
    } else {
      warningTips(response.message)
    }
  })
};

// //数据初始化
// onMounted(() => {
//   getTableData()
// })
//

defineExpose({
  getTableData
});
</script>
